package com.example.peibei.ui.adapter;

import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.dingtao.common.bean.Dynamic;
import com.dingtao.common.util.DateUtils;
import com.dingtao.common.util.GlideUtils;
import com.example.peibei.R;
import com.example.peibei.ui.utils.LevelImage;

import java.text.ParseException;
import java.util.List;

public class DynamicZanListAdapter extends BaseQuickAdapter<Dynamic.RecordsDTO, BaseViewHolder> {
    String status;

    public DynamicZanListAdapter(@Nullable List<Dynamic.RecordsDTO> data) {
        super(R.layout.item_dynamic_list, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Dynamic.RecordsDTO item) {
        ImageView head = helper.getView(R.id.iv_head);
        Glide.with(getContext()).load(item.getMember().getImgUrl()).apply(RequestOptions.bitmapTransform(new CircleCrop())).into(head);
        helper.setText(R.id.tv_name, item.getMember().getNickName()).setText(R.id.tv_dec, item.getTitle()).setText(R.id.tv_adress, item.getMember().getArea());
        ImageView iv_level = helper.getView(R.id.iv_level);//会员等级
        LevelImage.setLevelImage(item.getMember().getServiceLevel(), iv_level);
        List<Dynamic.RecordsDTO.ItemDTO> items = item.getItem();
        LinearLayout llImgs = helper.getView(R.id.ll_imgs);
        ImageView imgOne = helper.getView(R.id.iv_img_one);
        ImageView imgTwo = helper.getView(R.id.iv_img_two_dynamic);
        ImageView imgThree = helper.getView(R.id.iv_img_three);
        ImageView zan = helper.getView(R.id.zan);
        ImageView comment = helper.getView(R.id.comment);
        TextView zan_tv = helper.getView(R.id.zan_tv);
        TextView com_tv = helper.getView(R.id.com_tv);
        TextView time = helper.getView(R.id.time);
        time.setVisibility(View.GONE);
        if (items != null && items.size() > 0) {
            llImgs.setVisibility(View.VISIBLE);
            if (items.get(0) != null && !items.get(0).getUrl().equals("")) {
//                GlideUtils.loadImg(getContext(),items.get(0).getUrl(),20,imgOne);
                GlideUtils.loadImg(getContext(), items.get(0).getUrl(), 20, imgOne);
            }
            if (items.size() > 1 && items.get(1) != null && !items.get(1).getUrl().equals("")) {
//                GlideUtils.loadImg(getContext(),items.get(1).getUrl(),20,imgTwo);
                GlideUtils.loadImg(getContext(), items.get(1).getUrl(), 20, imgTwo);
            }
            if (items.size() > 2 && items.get(2) != null && !items.get(2).getUrl().equals("")) {
//                GlideUtils.loadImg(getContext(),items.get(2).getUrl(),20,imgThree);
                GlideUtils.loadImg(getContext(), items.get(2).getUrl(), 20, imgThree);
            }
        } else {
            llImgs.setVisibility(View.GONE);
        }
        zan.setImageResource(R.mipmap.zan_yellow);
        zan_tv.setText(String.valueOf(item.getFollow()));
        zan_tv.setTextColor(Color.parseColor("#9D9CD8"));

        if (item.getComment() != 0) {
            comment.setImageResource(R.mipmap.com_yellow);
            com_tv.setText(String.valueOf(item.getComment()));
            com_tv.setTextColor(Color.parseColor("#9D9CD8"));
        }


    }
}
